import io.netty.channel.ChannelId;
import java.util.HashMap;

public class ClientManager {

    private static ClientManager _instance;
    private HashMap<ChannelId, Client> clientHashMap = new HashMap<ChannelId, Client>();

    public static ClientManager Instance() {
        if (_instance == null) {
            _instance = new ClientManager();
        }

        return _instance;
    }

    public Client addClient(Client c) {
        if (c != null && !clientHashMap.containsKey(c.id)) {
            clientHashMap.put(c.id, c);
        }
        return c;
    }

    public void removeClient(Client c) {
        if (c != null && clientHashMap.containsKey(c.id)) {
            clientHashMap.remove(c.id);
        }
    }

    public Client getClient(ChannelId id) {
        return clientHashMap.get(id);
    }

    public void removeAllClients() {
        clientHashMap.clear();
    }
}
